/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { IEnvironmentService, ParsedArgs, IDebugParams, IExtensionHostDebugParams } from 'vs/platform/environment/common/environment';
//import * as crypto from 'crypto';
//import * as paths from 'vs/base/node/paths';
// import * as os from 'os';
//import * as path from 'path';
// import URI from 'vs/base/common/uri';
import { memoize } from 'vs/base/common/decorators';
//import pkg from 'vs/platform/node/package';
//import product from 'vs/platform/node/product';
// import { toLocalISOString } from 'vs/base/common/date';
//import { isWindows, isLinux } from 'vs/base/common/platform';

// Read this before there's any chance it is overwritten
// Related to https://github.com/Microsoft/vscode/issues/30624
//const xdgRuntimeDir = process.env['XDG_RUNTIME_DIR'];

// function getNixIPCHandle(userDataPath: string, type: string): string {
// 	if (xdgRuntimeDir) {
// 		return path.join(xdgRuntimeDir, `${pkg.name}-${pkg.version}-${type}.sock`);
// 	}

// 	return path.join(userDataPath, `${pkg.version}-${type}.sock`);
// }

// function getWin32IPCHandle(userDataPath: string, type: string): string {
// 	const scope = crypto.createHash('md5').update(userDataPath).digest('hex');

// 	return `\\\\.\\pipe\\${scope}-${pkg.version}-${type}-sock`;
// }

// function getIPCHandle(userDataPath: string, type: string): string {
// 	if (isWindows) {
// 		return getWin32IPCHandle(userDataPath, type);
// 	}

// 	return getNixIPCHandle(userDataPath, type);
// }

// function getCLIPath(execPath: string, appRoot: string, isBuilt: boolean): string {

// 	// Windows
// 	if (isWindows) {
// 		if (isBuilt) {
// 			return path.join(path.dirname(execPath), 'bin', `${product.applicationName}.cmd`);
// 		}

// 		return path.join(appRoot, 'scripts', 'code-cli.bat');
// 	}

// 	// Linux
// 	if (isLinux) {
// 		if (isBuilt) {
// 			return path.join(path.dirname(execPath), 'bin', `${product.applicationName}`);
// 		}

// 		return path.join(appRoot, 'scripts', 'code-cli.sh');
// 	}

// 	// macOS
// 	if (isBuilt) {
// 		return path.join(appRoot, 'bin', 'code');
// 	}

// 	return path.join(appRoot, 'scripts', 'code-cli.sh');
// }

export class EnvironmentService implements IEnvironmentService {

	_serviceBrand: any;

	get args(): ParsedArgs {
		return this._args;
	}

	@memoize
	get appRoot(): string {
		debugger
		throw new Error("不支持");
	}

	get execPath(): string {
		debugger
		throw new Error("不支持");
	}

	@memoize
	get cliPath(): string {
		debugger
		throw new Error("不支持");
	}

	readonly logsPath: string;

	@memoize
	get userHome(): string {
		return "";
	}

	@memoize
	get userDataPath(): string {
		debugger
		throw new Error("不支持");
	}

	get appNameLong(): string {
		return "代码城市";
	}

	get appQuality(): string {
		debugger
		throw new Error("不支持");
	}

	@memoize
	get appSettingsHome(): string {
		debugger
		throw new Error("不支持");
	}

	@memoize
	get appSettingsPath(): string {
		debugger
		throw new Error("不支持");
	}

	@memoize
	get settingsSearchBuildId(): number {
		debugger
		throw new Error("不支持");
	}

	@memoize
	get settingsSearchUrl(): string {
		debugger
		throw new Error("不支持");
	}

	@memoize
	get appKeybindingsPath(): string {
		debugger
		throw new Error("不支持");
	}

	@memoize
	get isExtensionDevelopment(): boolean {
		debugger
		throw new Error("不支持");
	}

	@memoize
	get backupHome(): string {
		debugger
		throw new Error("不支持");
	}

	@memoize
	get backupWorkspacesPath(): string {
		debugger
		throw new Error("不支持");
	}

	@memoize
	get workspacesHome(): string {
		debugger
		throw new Error("不支持");
	}

	@memoize
	get installSourcePath(): string {
		debugger
		throw new Error("不支持");
	}

	@memoize
	get extensionsPath(): string {
		return "extensions";
	}

	@memoize
	get extensionDevelopmentPath(): string {
		console.warn("extensionDevelopmentPath");
		return "";
	}

	@memoize
	get extensionTestsPath(): string {
		debugger
		throw new Error("不支持");
	}

	get disableExtensions(): boolean {
		return false;
	}

	get skipGettingStarted(): boolean { return false; }

	get skipReleaseNotes(): boolean { return true; }

	get skipAddToRecentlyOpened(): boolean { return true; }

	@memoize
	get debugExtensionHost(): IExtensionHostDebugParams {
		debugger
		throw new Error("不支持");
	}

	@memoize
	get debugSearch(): IDebugParams {
		debugger
		throw new Error("不支持");
	}

	get isBuilt(): boolean { return true; }
	get verbose(): boolean { return false; }

	get wait(): boolean {
		debugger
		throw new Error("不支持");
	}
	get logExtensionHostCommunication(): boolean {
		debugger
		throw new Error("不支持");
	}

	get performance(): boolean { return false; }
	get status(): boolean {
		debugger
		throw new Error("不支持");
	}

	@memoize
	get mainIPCHandle(): string {
		debugger
		throw new Error("不支持");
	}

	@memoize
	get sharedIPCHandle(): string {
		debugger
		throw new Error("不支持");
	}

	@memoize
	get nodeCachedDataDir(): string {
		debugger
		throw new Error("不支持");
	}

	get disableUpdates(): boolean { return true; }
	get disableCrashReporter(): boolean { return false; }
	constructor(private _args: ParsedArgs, private _exePath: string) {
		// this._args={_:[]};
		// this._args._.push("");
		this._exePath = "";
		this._exePath.charAt(0);
	}
}

export function parseExtensionHostPort(args: ParsedArgs, isBuild: boolean): IExtensionHostDebugParams {
	return parseDebugPort(args.debugPluginHost, args.debugBrkPluginHost, 5870, isBuild, args.debugId);
}

export function parseSearchPort(args: ParsedArgs, isBuild: boolean): IDebugParams {
	return parseDebugPort(args.debugSearch, args.debugBrkSearch, 5876, isBuild);
}

export function parseDebugPort(debugArg: string, debugBrkArg: string, defaultBuildPort: number, isBuild: boolean, debugId?: string): IExtensionHostDebugParams {
	const portStr = debugBrkArg || debugArg;
	const port = Number(portStr) || (!isBuild ? defaultBuildPort : null);
	const brk = port ? Boolean(!!debugBrkArg) : false;
	return { port, break: brk, debugId };
}

// function parsePathArg(arg: string, process: NodeJS.Process): string {
// 	if (!arg) {
// 		return undefined;
// 	}

// 	// Determine if the arg is relative or absolute, if relative use the original CWD
// 	// (VSCODE_CWD), not the potentially overridden one (process.cwd()).
// 	const resolved = path.resolve(arg);

// 	if (path.normalize(arg) === resolved) {
// 		return resolved;
// 	} else {
// 		return path.resolve(process.env['VSCODE_CWD'] || process.cwd(), arg);
// 	}
// }

// export function parseUserDataDir(args: ParsedArgs, process: NodeJS.Process): string {
// 	return parsePathArg(args['user-data-dir'], process) || path.resolve(paths.getDefaultUserDataPath(process.platform));
// }
